package cn.itsource.order.controller;

import cn.itsource.order.dto.OrderDto;
import cn.itsource.order.service.IOrderPetAcquisitionService;
import cn.itsource.order.domain.OrderPetAcquisition;
import cn.itsource.order.query.OrderPetAcquisitionQuery;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {

    @Autowired
    public IOrderPetAcquisitionService orderPetAcquisitionService;

    /**
     * 接口：添加或修改
     * @param orderPetAcquisition  传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody OrderPetAcquisition orderPetAcquisition){ 
        if( orderPetAcquisition.getId()!=null){
		orderPetAcquisitionService.update(orderPetAcquisition);
        }else{
                orderPetAcquisitionService.add(orderPetAcquisition);
	}
        return new AjaxResult();
       
    }

    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult del(@PathVariable("id") Long id){
        orderPetAcquisitionService.del(id);
        return new AjaxResult();
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids){
        orderPetAcquisitionService.patchDel(ids);
        return new AjaxResult();
    }

    /**
    * 接口：查询单个对象
    * @param id
    */
    @GetMapping("/{id}")
    public OrderPetAcquisition findOne(@PathVariable("id")Long id) {
        return orderPetAcquisitionService.findOne(id);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<OrderPetAcquisition> findAll(){
        return orderPetAcquisitionService.findAll();
    }


   /**
    * 接口：分页查询或高级查询
    * @param query 查询对象
    * @return PageList 分页对象
    */
//    @PostMapping
//    public PageList<OrderPetAcquisition> queryPage(@RequestBody OrderPetAcquisitionQuery query) {
//        return orderPetAcquisitionService.queryPage(query);
//    }

    /**
     * 接口：分页查询或高级查询:订单列表
     * @param query
     * @param request
     * @return
     */
    @PostMapping
    public PageList<OrderPetAcquisition> queryPage(@RequestBody OrderPetAcquisitionQuery query, HttpServletRequest request) {
        return orderPetAcquisitionService.queryPage(query,request);
    }

    /**
     * 取消订单
     * @param id
     * @return
     */
    @DeleteMapping(value="/cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id){
        return orderPetAcquisitionService.cancel(id);
    }

    /**
     * 确认订单
     */
    @PostMapping(value="/confirm")
    public AjaxResult confirm(@RequestBody OrderDto orderDto){
        return orderPetAcquisitionService.confirm(orderDto);
    }
}
